package com.smart.manager.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.system.entities.body.RLogLogin;
import com.smart.manager.system.entities.body.RLogOperation;
import com.smart.manager.system.entities.models.SystemLoginLog;
import com.smart.manager.system.entities.models.SystemOperationLog;
import com.smart.manager.system.repository.LogRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

 /**
 * 系统菜单- 前端API菜单
 * 当前页面的菜单需要超级管理员的角色才能登录
 *
 * @author xiaxuqiu
 */
 @Api(tags =  "日志管理")
 @RestController
 @RequestMapping(SmartConstant.MANAGER_API_PREFIX + "system/logs")
 @RequiredArgsConstructor
 public class LogLoginApi {

     private final LogRepository logRepository;



     @GetMapping("login")
     @ApiOperation(value = "查询登录日志")
     @SaCheckPermission("system:logs:login")
     public AjaxResult<Page<SystemLoginLog>> loginPageList(@Validated RLogLogin.SearchBody searchBody) {
         Page<SystemLoginLog> result = logRepository.getLoginLogPageList(searchBody) ;
         return AjaxResult.data(result);
     }




     @GetMapping("operation")
     @ApiOperation(value = "查询操作日志")
     @SaCheckPermission("system:logs:operation")
     public AjaxResult<Page<SystemOperationLog>> pageList(@Validated RLogOperation.SearchBody searchBody) {
         Page<SystemOperationLog> result = logRepository.getOperationLogPageList(searchBody) ;
         return AjaxResult.data(result);
     }
 }
